
#make figures money outcomes

main_df <- main_df %>% mutate(group.treatment = factor(group.treatment, levels = c("random", "merit", "patronage")))

#how much keep?

keep_bivariate <-lm(group.dictator_payoff/1000 ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1))
herf_bivariate <- lm(herf_index_payout ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1))
other_bivariate <- lm(perc_other ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1))

keep_covariate <-lm(group.dictator_payoff/1000 ~ factor(group.treatment) + player.age + factor(player.education == 4), main_df %>% filter(pub_official_indicator == 1))
herf_covariate <- lm(herf_index_payout ~ factor(group.treatment) + player.age +  factor(player.education == 4), main_df %>% filter(pub_official_indicator == 1))
other_covariate <- lm(perc_other ~ factor(group.treatment) + player.age +  factor(player.education == 4), main_df %>% filter(pub_official_indicator == 1))

observations <- c(nobs(keep_bivariate),nobs(herf_bivariate),nobs(other_bivariate),nobs(keep_covariate),nobs(herf_covariate),nobs(other_covariate))

keep_bivariate <- coeftest(keep_bivariate, vcov=vcovHC(keep_bivariate,type="HC0"))
herf_bivariate <- coeftest(herf_bivariate, vcov=vcovHC(herf_bivariate,type="HC0"))
other_bivariate <- coeftest(other_bivariate, vcov=vcovHC(other_bivariate,type="HC0"))
keep_covariate <- coeftest(keep_covariate, vcov=vcovHC(keep_covariate,type="HC0"))
herf_covariate <- coeftest(herf_covariate, vcov=vcovHC(herf_covariate,type="HC0"))
other_covariate <- coeftest(other_covariate, vcov=vcovHC(other_covariate,type="HC0"))

table <- list(keep_bivariate, herf_bivariate, other_bivariate, keep_covariate, herf_covariate, other_covariate)

note_text <- paste("Beta coefficients from OLS regression. Standard errors were calculated using the Huber-White (HC0) correction. 
                   The outcomes measures are the (1) absolute sum kept by the public officials; (2) a herfindahl index of participant shares; (3) the percent
                   of money given to other participants.")

table = stargazer(table, type = 'latex', 
                  title = "The Effect of Selection Mode on Pro-Sociality",
                  label = 'tab:pro_soc',
                  model.names = F,
                  model.numbers = T,
                  digits = 3,
                  column.separate = c(1,1 , 1, 1, 1, 1),
                  column.labels = c("Keep (IDR, k)", "Herf. Index (0-1)", "Share (\\%)", "Keep (IDR, k)", "Herf. Index (0-1)", "Share (\\%)"),
                  dep.var.labels = NULL, 
                  add.lines = list(c("Covariates", "N", "N", "N", "Y", "Y", "Y"),
                                   c("Observations", observations)),
                  #omit = c("player.age", "player.education"),
                  covariate.labels = c("Treatment: Merit", "Treatment: Patronage", "Age", "Education: College", "Constant"),
                  
                  #star.cutoffs = c(0.05, 0.01),
                  #float.env = 'sidewaystable',
                  keep.stat = c("n"),
                  notes = NULL,
                  notes.align = 'l')

write_latex(table[-c(10, 11, 12, 18, 21, 24, 27, 30, 36)], note_text, './outputs/tables/table_a5.tex', .8)

